package com.itfitness.googlemappoi.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.LogUtils
import com.itfitness.googlemappoi.bean.GeocodeAddressBean
import com.itfitness.googlemappoi.http.putValue2Data
import com.itfitness.googlemappoi.http.RetrofitManger
import kotlinx.coroutines.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class MainModel:ViewModel(){
    var userInfo = MutableLiveData<GeocodeAddressBean>()
    /**
     * 根据经纬度获取地址
     */
    fun getAddress(latitude: Double, longitude: Double){
        viewModelScope.launch {
            val latlng = "$latitude,$longitude"
            val fields = "formatted_address,name,rating,geometry"
            val key = "你的静态APIKey"
            RetrofitManger.getApiService().getAddress(
                latlng, "zh", fields, key
            ).putValue2Data(GeocodeAddressBean::class.java,userInfo)
        }
    }
}